home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / envman.lha / EnvManager / rcs / enventry.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-23  |  2.2 KB  |  136 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.1; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.1
  10. date    96.08.23.16.57.28;    author dlorre;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @EnvManager : Gestionnaire d'Environnement
  17. Auteur : Dominique Lorre
  18. @
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @#include <exec/types.h>
  27. #include <cxxproto/exec.h>
  28. #include <string.h>
  29.  
  30. #include "envdef.h"
  31. #include "enventry.h"
  32.  
  33. IMPORT nlist *envarclist ;
  34. IMPORT nlist *envlist ;
  35. IMPORT nlist *envloclist ;
  36.  
  37. enventry *findname(nlist *l, STRPTR name)
  38. {
  39. enventry *c = (enventry *)l->first() ;
  40.  
  41.     while (c && stricmp(c->name, name))
  42.         c = (enventry *)c->next() ;
  43.     return c ;
  44. }
  45.  
  46. enventry *findvar(STRPTR name)
  47. {
  48. enventry    *ev = NULL ;
  49.  
  50.     if (ev = findname(envlist, name))
  51.         return ev ;
  52.     if (ev = findname(envloclist, name))
  53.         return ev ;
  54.     ev = findname(envarclist, name) ;
  55.         return ev ;
  56. }
  57.  
  58.  
  59. enventry::enventry(STRPTR n, STRPTR c, long s, char t)
  60. {
  61.     size = s ;
  62.     name = new char[strlen(n)+1] ;
  63.     strcpy(name, n) ;
  64.     label = entry ;
  65.     contents = new char[size+1] ;
  66.     CopyMem(c, contents, size) ;
  67.     contents[size] = '\0' ;
  68.     type = t ;
  69.     setentry() ;
  70. }
  71.  
  72.  
  73. void enventry::setentry()
  74. {
  75. int i ;
  76.  
  77.     binary = FALSE ;
  78.     notnullterm = FALSE ;
  79.     for (i=0; i<size && !binary; i++) {
  80.         binary =  (UBYTE(contents[i]) < ' ' && contents[i] != 0x0A) || ((contents[i] == 0x0A) && (i<size-1)) ;
  81.     }
  82.  
  83.     if (binary) {
  84.         for (i=0; i<size && !notnullterm ; i++) {
  85.             notnullterm = contents[i] == 0x00 ;
  86.         }
  87.     }
  88.     else
  89.         notnullterm = FALSE ;
  90.  
  91.     strncpy(entry, name, MAXNAME) ;
  92.     strcat(entry, " ") ;
  93.     while(strlen(entry) < MAXNAME)
  94.         strcat(entry, " ") ;
  95.     if (type == ALIAS_TYPE) {
  96.         strcat(entry, "[ALIAS] ") ;
  97.     }
  98.     strncat(entry, contents, MAXCONTENTS) ;
  99. }
  100.  
  101. enventry::~enventry()
  102. {
  103.     delete name ;
  104.     delete contents ;
  105. }
  106.  
  107. BOOL enventry::islocale()
  108. {
  109.     return (type == LOCAL_TYPE) ;
  110. }
  111. BOOL enventry::isalias()
  112. {
  113.     return (type == ALIAS_TYPE) ;
  114. }
  115. BOOL enventry::isglobal()
  116. {
  117.     return findname(envlist, name) != NULL ;
  118. }
  119.  
  120. BOOL enventry::isarchived()
  121. {
  122.     return findname(envarclist, name) != NULL ;
  123. }
  124.  
  125. BOOL enventry::isbinary()
  126. {
  127.     return binary ;
  128. }
  129.  
  130. BOOL enventry:: isnullterm()
  131. {
  132.     return !notnullterm ;
  133. }
  134.  
  135. @
  136.